package com.tianqu.tms.www.car.controller;

import java.util.ArrayList;
import java.util.List;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.entity.MarketCarGateInfo;

/**
 * @author Administrator  huangwei st2
 *
 */
public class CarInoutHistoryController  extends TmsController{
	private Logger logger = Logger.getLogger(CarInoutHistoryController.class);

	@Override
	public void execute(UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controllor = TxController.getTxController();
		try {
			controllor.begin();
			
			//
			String serial = (String)uc.getAttribute("serial");
			String licensePlate = (String)uc.getAttribute("licensePlate");
			MarketCarGateInfo marketCarGateInfo = MarketCarGateInfo.getInstance();
			//
			int i=1;
			List<MarketCarGateInfo> r = new ArrayList<MarketCarGateInfo>();
			for(MarketCarGateInfo info : marketCarGateInfo.findAllGateInfoBySerial(serial)){
			   if(i>30) break;  i++;
			   r.add(info);
			}
			//
			uc.setAttribute(TmsConstants.VIEWHELP, r);
			logger.debug(this.getClass().getName() + "#execute was completed.");
			controllor.commit();
		} catch (Exception e) {
			try {
				controllor.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			// 系统异常
			if (e instanceof TmsException) {
				throw e;
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}
		
	}

}
